<template>
		<div>
			<select  name="firCate" v-on:change="cateChange(1,$event)">
				<option v-for="item in firCateList" :key="item.id" v-bind:value="item.id" >{{item.name}}</option>
			</select>
			
			<select  name="secCate" v-on:change="cateChange(2,$event)">
				<option v-for="item in secCateList" :key="item.id" v-bind:value="item.id" >{{item.name}}</option>
			</select>
			
			<select name="thrCate">
				<option v-for="item in thrCateList" :key="item.id" v-bind:value="item.id" >{{item.name}}</option>
			</select>
		</div>
</template>


<script>
	var  lazyInfo={
			"-1":[{"id":"-1","name":"-请选择-"}],
			"0":[{"id":"-1","name":"-请选择-"},{"id":"1","name":"一级分类"},{"id":"2","name":"一级分类2"}],
			"1":[{"id":"-1","name":"-请选择-"},{"id":"20","name":"二级分类1"},{"id":"21","name":"二级分类2"}],
			"2":[{"id":"-1","name":"-请选择-"},{"id":"25","name":"二级分类5"},{"id":"26","name":"二级分类6"}],
			"20":[{"id":"-1","name":"-请选择-"},{"id":"30","name":"三级分类1"},{"id":"31","name":"三级分类2"},{"id":"32","name":"三级分类3"}],
			"21":[{"id":"-1","name":"-请选择-"},{"id":"35","name":"三级分类5"},{"id":"36","name":"三级分类6"},{"id":"37","name":"三级分类7"}],
			"25":[{"id":"-1","name":"-请选择-"},{"id":"38","name":"三级分类8"},{"id":"39","name":"三级分类9"},{"id":"391","name":"三级分类391"}],
			"26":[{"id":"-1","name":"-请选择-"},{"id":"392","name":"三级分类391"},{"id":"393","name":"三级分类393"},{"id":"394","name":"三级分类394"}]
			};


	function fetchChildByParentId(parentId,obj,callback){
		var lazyCate=lazyInfo[parentId];
		if(lazyCate){
			callback.call(obj,lazyCate);
		}
	}


	module.exports={
		name:"Address",
		data:function(){
			return {
					"firCateList": [{"id":"-1","name":"-请选择-"}],
					"secCateList": [{"id":"-1","name":"-请选择-"}],
					"thrCateList": [{"id":"-1","name":"-请选择-"}]
				   };
		},
		created:function(){
			//获取一级分类信息
			fetchChildByParentId(0,this,function(data){
				this.firCateList=data;
			});
		},
		methods:{
			"cateChange":function(index,event){
				var val=event.target.value;
				var _this=this;
				fetchChildByParentId(val,this,function(cateInfo){
					if(index==1){
						_this.secCateList=cateInfo;	
						_this.thrCateList=[{"id":"-1","name":"-请选择-"}];
					}else if(index==2){
						_this.thrCateList=cateInfo;	
					}
				});

			}
		}
	}

</script>